// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: V Block Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 53 : TYPE_VBLOCK

// Function declarations
reserve function VBlock_DebugDraw
reserve function VBlock_DebugSpawn

// Static Values
private value value0xF33E = 0;

// Tables

function VBlock_DebugDraw
	DrawSprite(0)
end function


function VBlock_DebugSpawn
	CreateTempObject(TypeName[V Block], object.direction, object.xpos, object.ypos)
	if object[tempObjectPos].propertyValue == 1
		object[tempObjectPos].ypos -= 0x200000
	else
		object[tempObjectPos].ypos -= 0x1F0000
	end if
end function


event ObjectMain
	object.angle = SYZSetup_value29
	object.angle *= 512
	object.angle /= 356
	if object.propertyValue == 1
		object.angle += 256
	end if
	object.angle &= 511
	Sin(object.value2, object.angle)
	object.value2 <<= 12
	object.value2 += object.ypos
	object.value2 &= -0x10000
	object.value2 -= object.value1
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		temp0 = object.ypos
		object.ypos = object.value1
		BoxCollisionTest(C_BOX, object.entityPos, -32, -32, 32, 32, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		switch checkResult
		case 1
			object[currentPlayer].ypos += object.value2
			break
		case 4
			if object[currentPlayer].gravity == GRAVITY_GROUND
				if object.angle > 384
					CallFunction(PlayerObject_Kill)
				end if
				if object.angle < 128
					CallFunction(PlayerObject_Kill)
				end if
			end if
		end switch
		object.ypos = temp0
	next
end event


event ObjectDraw
	Sin(object.value1, object.angle)
	object.value1 <<= 12
	object.value1 += object.ypos
	object.value1 &= -0x10000
	DrawSpriteXY(0, object.xpos, object.value1)
end event


event ObjectStartup
	LoadSpriteSheet("SYZ/Objects.gif")
	SpriteFrame(-32, -32, 64, 64, 119, 34)
	foreach (TypeName[V Block], arrayPos0, ALL_ENTITIES)
		if object[arrayPos0].propertyValue == 1
			object[arrayPos0].ypos -= 0x200000
		else
			object[arrayPos0].ypos -= 0x1F0000
		end if
	next
	SetTableValue(TypeName[V Block], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(VBlock_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(VBlock_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
